/*
 * WebCrawlerGUIView.java
 */

package nz.ac.massey.spidernetpn.webcrawlergui;

import nz.ac.massey.spidernetpn.database.GraphDatabase;
import nz.ac.massey.spidernetpn.webcrawler.FoundMaxException;
import nz.ac.massey.spidernetpn.webcrawler.WebCrawler;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;

import edu.uci.ics.jung.graph.DirectedGraph;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

import edu.uci.ics.jung.algorithms.layout.*;
import edu.uci.ics.jung.algorithms.layout.util.Relaxer;
import edu.uci.ics.jung.algorithms.layout.util.VisRunner;
import edu.uci.ics.jung.algorithms.util.IterativeContext;
import edu.uci.ics.jung.graph.DirectedGraph;
import edu.uci.ics.jung.graph.DirectedSparseMultigraph;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.ObservableGraph;
import edu.uci.ics.jung.graph.event.GraphEvent;
import edu.uci.ics.jung.graph.event.GraphEventListener;
import edu.uci.ics.jung.graph.util.Graphs;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ScalingControl;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.layout.LayoutTransition;
import edu.uci.ics.jung.visualization.renderers.*;
import edu.uci.ics.jung.visualization.util.Animator;

/**
 * The application's main frame.
 */
public class WebCrawlerGUIView extends FrameView {

	private static WebCrawler crawler;
	private DirectedGraph<URL,Integer> graph;
	
    public WebCrawlerGUIView(SingleFrameApplication app) {
        super(app);

        initComponents();
        
        setupWebCrawler();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = WebCrawlerGUIApp.getApplication().getMainFrame();
            aboutBox = new WebCrawlerGUIAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        WebCrawlerGUIApp.getApplication().show(aboutBox);
    }
   
    //--------------------------------------------------------------------------------------------
    //********************************************************************************************
    //Main Custom Code Start
    //********************************************************************************************
    //--------------------------------------------------------------------------------------------
    
    private void setupWebCrawler(){
    	
    	crawler = new WebCrawler(this.jCheckBox_UseProxy.isSelected());
    	graph = crawler.getGraph();
    	crawler.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				CrawlerFoundMoreURLs();
			}
		});
    	          
        Layout<URL, Integer> layout = new FRLayout2<URL, Integer>(graph);
		layout.setSize(new Dimension(800,800)); // sets the initial size of the layout space
		Dimension preferredSize = new Dimension(1000,1000);
		vs = new BasicVisualizationServer<URL, Integer>(layout, preferredSize);
		vs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<URL>());

		
    }
    
    private GraphDatabase graphDB = new GraphDatabase();
    private BasicVisualizationServer<URL, Integer> vs;
   // private VisualizationViewer vv;
  
    public void GoButtonStartCrawl() {
    	setupWebCrawler();
    	jScrollPane_GraphDrawingArea.removeAll();
    	jScrollPane_GraphDrawingArea.add(vs);
    	vs.revalidate();
    	//jScrollPane_GraphDrawingArea.removeAll();
    	System.out.println("Starting the Crawler");
    		//Submit URL to crawler
    		try {
    			crawler.submit(jTextField_EnterURLText.getText());
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (FoundMaxException e) {
    			e.printStackTrace();
    		}

    }
    
    public void CrawlerFoundMoreURLs(){
    	//graph = crawler.getGraph();
    	Integer vertexCount = graph.getVertexCount();
    	this.jLabel_NodeCounter.setText(vertexCount.toString());
    	
		if((vertexCount%20==0)||(vertexCount<10&&vertexCount>1)){
			System.out.println("An action has been called");	
			System.out.println("Drawn something new I hope. Size: " + vertexCount);
			
			vs.repaint();
			
		}
		if(vertexCount==75){
			//FOr testing stop after 200 nodes
			System.out.println("Stopping the Crawler");
			crawler.stop();
		}
    	
    }
    
    
    private void RedrawGraph(){
    	System.out.println("Redrawing");
    	Layout<URL, Integer> layout = new FRLayout2<URL, Integer>(graph);
		layout.setSize(new Dimension(800,800)); // sets the initial size of the layout space
		Dimension preferredSize = new Dimension(1001,1001);
		vs = new BasicVisualizationServer<URL, Integer>(layout, preferredSize);
		vs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<URL>());
		
		jScrollPane_GraphDrawingArea.removeAll();
		jScrollPane_GraphDrawingArea.add(vs);
		//vs.repaint();
		vs.revalidate();
    }
    
    private void DisplayLoadGraphDialog(){
    	jDialog_LoadGraph.pack();
    	
    	jList_GraphList.setModel(new javax.swing.AbstractListModel() {
            List strings = graphDB.getListOfStoredGraphs();
            public int getSize() { return strings.size(); }
            public Object getElementAt(int i) { return strings.toArray()[i]; }
        });
    
    	this.jDialog_LoadGraph.setVisible(true);
    }
    
    
    private void DisplaySaveGraphDialog(){
    	jDialog_SaveGraph.pack();
    	this.jDialog_SaveGraph.setVisible(true);
    	
    }
    
    //Save graph button, get file name and save graph
    private void SaveGraphDialogSave(){
    	System.out.println("Trying to save graph");
    	String fileName = jTextField_GraphName.getText();
    	if(graphDB.saveGraph(fileName, graph)){
    		System.out.println("Graph saved as "+fileName);
    	} else {
    		System.out.println("Graph save failed");
    	}

    	this.jDialog_SaveGraph.setVisible(false);
    	
    }
    
    //Load graph button, get file name and load graph
    private void LoadGraphDialogOk(){
    	System.out.println("Trying to load graph");
    	int SelectedGraphIndex = this.jList_GraphList.getSelectedIndex();
    	
    	if(SelectedGraphIndex!=-1){
    		List avaliableGraphs = graphDB.getListOfStoredGraphs();
    		
    		DirectedGraph<URL,Integer> loadedGraph;
    		try {
				loadedGraph = graphDB.loadCustomGraphNEW((String)avaliableGraphs.toArray()[SelectedGraphIndex]);
				System.out.println("Graph Should now load"+loadedGraph.toString());   
				graph = loadedGraph;
	            Layout<URL, Integer> layout = new FRLayout2<URL, Integer>(graph);
	    		layout.setSize(new Dimension(800,800)); // sets the initial size of the layout space
	    		Dimension preferredSize = new Dimension(1000,1000);
	    		vs = new BasicVisualizationServer<URL, Integer>(layout, preferredSize);
	    		vs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<URL>());
	    		jScrollPane_GraphDrawingArea.removeAll();
	    		jScrollPane_GraphDrawingArea.add(vs);
	    		//jScrollPane_GraphDrawingArea.validate();
	    		vs.revalidate();
	    		System.out.println("Done");
	    		vs.repaint();
			} catch (Exception e) {
				System.out.println("Graph failed to load");
				e.printStackTrace();
				return;
			}

    	}
    	Integer vertexCount = graph.getVertexCount();
    	this.jLabel_NodeCounter.setText(vertexCount.toString());
    	this.jDialog_LoadGraph.setVisible(false);
    	
    }
    
    
    //--------------------------------------------------------------------------------------------
    //********************************************************************************************
    //Main Custom Code END
    //********************************************************************************************
    //--------------------------------------------------------------------------------------------
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel_GraphToolBar = new javax.swing.JPanel();
        jButton_StopCrawl = new javax.swing.JButton();
        jTextField_EnterURLText = new javax.swing.JTextField();
        jLabel_URL = new javax.swing.JLabel();
        jButton_GoStartCrawl = new javax.swing.JButton();
        jButton_ReDraw = new javax.swing.JButton();
        jCheckBox_UseProxy = new javax.swing.JCheckBox();
        jScrollPane_GraphDrawingArea = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem_LoadGraph = new javax.swing.JMenuItem();
        jMenuItem_SaveGraph = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        jLabel_NodeCountText = new javax.swing.JLabel();
        jLabel_NodeCounter = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jDialog_LoadGraph = new javax.swing.JDialog();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList_GraphList = new javax.swing.JList();
        jLabel_SelectGraphToLoad = new javax.swing.JLabel();
        jButton_LoadGraphCancel = new javax.swing.JButton();
        jButton_LoadGraphOk = new javax.swing.JButton();
        jDialog_SaveGraph = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        jTextField_GraphName = new javax.swing.JTextField();
        jButton_SaveGraphCancel = new javax.swing.JButton();
        jButton_SaveGraph = new javax.swing.JButton();

        mainPanel.setName("mainPanel"); // NOI18N

        jPanel_GraphToolBar.setName("jPanel_GraphToolBar"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(nz.ac.massey.spidernetpn.webcrawlergui.WebCrawlerGUIApp.class).getContext().getResourceMap(WebCrawlerGUIView.class);
        jButton_StopCrawl.setText(resourceMap.getString("jButton_StopCrawl.text")); // NOI18N
        jButton_StopCrawl.setName("jButton_StopCrawl"); // NOI18N
        jButton_StopCrawl.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				crawler.stop();
				jScrollPane_GraphDrawingArea.repaint();
				vs.repaint();
			}
		});

        jTextField_EnterURLText.setText(resourceMap.getString("jTextField_EnterURLHere.text")); // NOI18N
        jTextField_EnterURLText.setName("jTextField_EnterURLHere"); // NOI18N

        jLabel_URL.setText(resourceMap.getString("jLabel_URL.text")); // NOI18N
        jLabel_URL.setName("jLabel_URL"); // NOI18N

        jButton_GoStartCrawl.setText(resourceMap.getString("jButton_GoStartCrawl.text")); // NOI18N
        jButton_GoStartCrawl.setName("jButton_GoStartCrawl"); // NOI18N
        jButton_GoStartCrawl.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				GoButtonStartCrawl();
			}
		});
        
        jButton_ReDraw.setText(resourceMap.getString("jButton_ReDraw.text")); // NOI18N
        jButton_ReDraw.setName("jButton_ReDraw"); // NOI18N
        jButton_ReDraw.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				RedrawGraph();
			}
		});

        jCheckBox_UseProxy.setText(resourceMap.getString("jCheckBox_UseProxy.text")); // NOI18N
        jCheckBox_UseProxy.setName("jCheckBox_UseProxy"); // NOI18N

        javax.swing.GroupLayout jPanel_GraphToolBarLayout = new javax.swing.GroupLayout(jPanel_GraphToolBar);
        jPanel_GraphToolBar.setLayout(jPanel_GraphToolBarLayout);
        jPanel_GraphToolBarLayout.setHorizontalGroup(
            jPanel_GraphToolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_GraphToolBarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_URL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_EnterURLText, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_GoStartCrawl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_StopCrawl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_ReDraw)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 166, Short.MAX_VALUE)
                .addComponent(jCheckBox_UseProxy)
                .addContainerGap())
        );
        jPanel_GraphToolBarLayout.setVerticalGroup(
            jPanel_GraphToolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_GraphToolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jTextField_EnterURLText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel_URL)
                .addComponent(jButton_GoStartCrawl)
                .addComponent(jButton_StopCrawl)
                .addComponent(jButton_ReDraw)
                .addComponent(jCheckBox_UseProxy))
                
        );

        jScrollPane_GraphDrawingArea.setName("jScrollPane_GraphDrawingArea"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel_GraphToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane_GraphDrawingArea, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jPanel_GraphToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane_GraphDrawingArea, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem_LoadGraph.setText(resourceMap.getString("jMenuItem_LoadGraph.text")); // NOI18N
        jMenuItem_LoadGraph.setName("jMenuItem_LoadGraph"); // NOI18N
        jMenuItem_LoadGraph.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				 DisplayLoadGraphDialog();
			}
		});
        fileMenu.add(jMenuItem_LoadGraph);

        jMenuItem_SaveGraph.setText(resourceMap.getString("jMenuItem_SaveGraph.text")); // NOI18N
        jMenuItem_SaveGraph.setName("jMenuItem_SaveGraph"); // NOI18N
        jMenuItem_SaveGraph.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				 DisplaySaveGraphDialog();
			}
		});
        fileMenu.add(jMenuItem_SaveGraph);
        

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(nz.ac.massey.spidernetpn.webcrawlergui.WebCrawlerGUIApp.class).getContext().getActionMap(WebCrawlerGUIView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N
        
        jLabel_NodeCountText.setText(resourceMap.getString("jLabel_NodeCountText.text")); // NOI18N
        jLabel_NodeCountText.setName("jLabel_NodeCountText"); // NOI18N

        jLabel_NodeCounter.setText(resourceMap.getString("jLabel_NodeCounter.text")); // NOI18N
        jLabel_NodeCounter.setName("jLabel_NodeCounter"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusMessageLabel)
                    .addComponent(jLabel_NodeCountText))
                .addGap(10, 10, 10)
                .addComponent(jLabel_NodeCounter)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 425, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 2, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                        .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(statusMessageLabel)
                            .addComponent(statusAnimationLabel)
                            .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(3, 3, 3))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_NodeCountText)
                        .addComponent(jLabel_NodeCounter))))
        );

        jDialog_LoadGraph.setName("jDialog_LoadGraph"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jList_GraphList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Error 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList_GraphList.setName("jList_GraphList"); // NOI18N
        
        jScrollPane1.setViewportView(jList_GraphList);

        jLabel_SelectGraphToLoad.setText(resourceMap.getString("jLabel_SelectGraphToLoad.text")); // NOI18N
        jLabel_SelectGraphToLoad.setName("jLabel_SelectGraphToLoad"); // NOI18N

        jButton_LoadGraphCancel.setText(resourceMap.getString("jButton_LoadGraphCancel.text")); // NOI18N
        jButton_LoadGraphCancel.setName("jButton_LoadGraphCancel"); // NOI18N
        jButton_LoadGraphCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				jDialog_LoadGraph.setVisible(false);
			}
		});

        jButton_LoadGraphOk.setText(resourceMap.getString("jButton_LoadGraphOk.text")); // NOI18N
        jButton_LoadGraphOk.setName("jButton_LoadGraphOk"); // NOI18N
        jButton_LoadGraphOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				LoadGraphDialogOk();
			}
		});

        javax.swing.GroupLayout jDialog_LoadGraphLayout = new javax.swing.GroupLayout(jDialog_LoadGraph.getContentPane());
        jDialog_LoadGraph.getContentPane().setLayout(jDialog_LoadGraphLayout);
        jDialog_LoadGraphLayout.setHorizontalGroup(
            jDialog_LoadGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog_LoadGraphLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialog_LoadGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel_SelectGraphToLoad)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog_LoadGraphLayout.createSequentialGroup()
                        .addComponent(jButton_LoadGraphOk)
                        .addGap(3, 3, 3)
                        .addComponent(jButton_LoadGraphCancel)))
                .addContainerGap())
        );
        jDialog_LoadGraphLayout.setVerticalGroup(
            jDialog_LoadGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog_LoadGraphLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLabel_SelectGraphToLoad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jDialog_LoadGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_LoadGraphOk)
                    .addComponent(jButton_LoadGraphCancel))
                .addContainerGap())
        );

        jDialog_SaveGraph.setName("jDialog_SaveGraph"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextField_GraphName.setText(resourceMap.getString("jTextField_GraphName.text")); // NOI18N
        jTextField_GraphName.setName("jTextField_GraphName"); // NOI18N

        jButton_SaveGraphCancel.setText(resourceMap.getString("jButton_SaveGraphCancel.text")); // NOI18N
        jButton_SaveGraphCancel.setName("jButton_SaveGraphCancel"); // NOI18N
        jButton_SaveGraphCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				jDialog_SaveGraph.setVisible(false);
			}
		});

        jButton_SaveGraph.setText(resourceMap.getString("jButton_SaveGraph.text")); // NOI18N
        jButton_SaveGraph.setName("jButton_SaveGraph"); // NOI18N
        jButton_SaveGraph.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SaveGraphDialogSave();
			}
		});

        javax.swing.GroupLayout jDialog_SaveGraphLayout = new javax.swing.GroupLayout(jDialog_SaveGraph.getContentPane());
        jDialog_SaveGraph.getContentPane().setLayout(jDialog_SaveGraphLayout);
        jDialog_SaveGraphLayout.setHorizontalGroup(
            jDialog_SaveGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog_SaveGraphLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDialog_SaveGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_GraphName, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog_SaveGraphLayout.createSequentialGroup()
                        .addComponent(jButton_SaveGraph)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_SaveGraphCancel)))
                .addContainerGap())
        );
        jDialog_SaveGraphLayout.setVerticalGroup(
            jDialog_SaveGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog_SaveGraphLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_GraphName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(jDialog_SaveGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_SaveGraphCancel)
                    .addComponent(jButton_SaveGraph))
                .addContainerGap())
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_GoStartCrawl;
    private javax.swing.JButton jButton_LoadGraphCancel;
    private javax.swing.JButton jButton_LoadGraphOk;
    private javax.swing.JButton jButton_SaveGraph;
    private javax.swing.JButton jButton_SaveGraphCancel;
    private javax.swing.JButton jButton_StopCrawl;
    private javax.swing.JButton jButton_ReDraw;
    private javax.swing.JCheckBox jCheckBox_UseProxy;
    private javax.swing.JDialog jDialog_LoadGraph;
    private javax.swing.JDialog jDialog_SaveGraph;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_NodeCountText;
    private javax.swing.JLabel jLabel_NodeCounter;
    private javax.swing.JLabel jLabel_SelectGraphToLoad;
    private javax.swing.JLabel jLabel_URL;
    private javax.swing.JList jList_GraphList;
    private javax.swing.JMenuItem jMenuItem_LoadGraph;
    private javax.swing.JMenuItem jMenuItem_SaveGraph;
    private javax.swing.JPanel jPanel_GraphToolBar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jScrollPane_GraphDrawingArea;
    private javax.swing.JTextField jTextField_EnterURLText;
    private javax.swing.JTextField jTextField_GraphName;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
